package ocg.http.httpcore;

import com.alibaba.fastjson.JSONObject;

import java.util.Map;

public class Post extends HttpModel {

    public Post(String url ) {
        this.url  = url;
        this.model = "post";
    }

    @Override
    public Post headers(Map<String,String> headers){
        for (String s : headers.keySet ()) {
            this.headers.put ( s,headers.get ( s ) );
        }
        return this;
    }
    @Override
    public Post header(String key , String value ){
        this.headers.put( key , value );
        return this;
    }
    @Override
    public Post cookies( Map<String,String> cookies ){
        for (String s : cookies.keySet ()) {
            this.cookies.put ( s, cookies.get ( s ) );
        }
        return this;
    }
    @Override
    public Post cookie( String key , String value ){
        this.cookies.put( key , value );
        return this;
    }
    @Override
    public Post body( String Body ){
        this.body = Body;
        return this;
    }
    @Override
    public Post parameter(String key, String value) {
        this.parameters.put ( key,value );
        return this;
    }
    @Override
    public Post parameters(Map <String, String> parameters) {
        for (String s : parameters.keySet ()) {
            this.parameters.put ( s , parameters.get ( s ) );
        }
        return this;
    }

    public Post body( JSONObject jsonBody ){
        this.body = jsonBody.toString ();
        return this;
    }

    public Post asJson(){
        this.headers.put( "content-type" , "application/json" );
        return this;
    }
}
